/*
 * SFTPConnection.h
 *
 *  Created on: Mar 14, 2011
 *      Author: sms103
 */

#ifndef SFTPCONNECTION_H_
#define SFTPCONNECTION_H_

#include "TCPSocket.h"
#include "SFTPMessage.h"
#include "SFTPTransportSocket.h"
#include "EmulatedNetworkSocket.h"
#include "../shared/ParamParser.h"
#include <pthread.h>
#include <sys/types.h>
#include <iostream>

using namespace std;



class SFTPConnection {
public:

	/* Must construct on an open TCPSocket object. isActive is true if this is the
	 * active (client) side of the connection, or false if this is the passive(server) side*/
	SFTPConnection(TCPSocket *sock, bool isActive, ParamParser *paramParser);

	/* initialize the connection (three way handshake).
	 * Must be called before trying to use the connection.*/
	bool init();

	/* sends a message object. if message fits in send buffer, this returns immediately, else
	 * it returns when there is enough room in the send buffer and it has been copied.	Returns
	 * true on success, false if the connection has failed. */
	bool sendMessage(SFTPMessage *msg);

	/* Blocks until an entire SFTPMessage object is ready. Fills in the provided SFTPMessage
	 * object. returns false if there was an error during reception*/
	bool recvMessage(SFTPMessage *msg);

	void clearStats();
	transport_stats * getTranspStats();
	network_stats * getNetworkStats();
	string getDescriptorString();

	void close();

	bool isOpen();
	bool isActive();

	uint32_t getTransportMSS();

	virtual ~SFTPConnection();

	ParamParser *paramParser;

private:
	SFTPTransportSocket *transpSocket;
	bool active;

	bool isOpenVar;


};

#endif /* SFTPCONNECTION_H_ */
